package com.ymatou.iapi.reachpromotion.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.marketingmanage.parameter.CreateSellerPromotionBean;
import com.ymatou.iapi.reachpromotion.parameter.GetPromotionProductByIdBean;
import com.ymatou.iapi.reachpromotion.parameter.GetPromotionProductByIdResp;
import com.ymatou.iapi.reachpromotion.parameter.PromotionPolicy;
import com.ymatou.iapi.reachpromotion.service.GetPromotionProductByIdCall;
import com.ymatou.iapi.reachpromotion.service.PromotionInfoVerify;
import com.ymatou.iapi.trading.operate.parameter.enums.PromotionTypeEnum;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JSellerPromotionCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.compare.AssertHelper;
/**
*根据促销ID、买手ID获取促销商品信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetPromotionProductById{
	private static GetPromotionProductByIdBean getpromotionproductbyidBean;
	private static GetPromotionProductByIdCall getpromotionproductbyidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据促销ID、买手ID获取促销商品信息");
	}

	@Before
	public void caseUp() {
		getpromotionproductbyidBean=new GetPromotionProductByIdBean();
		getpromotionproductbyidCall=new GetPromotionProductByIdCall();
	}    

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpromotionproductbyidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromotionProductById_001() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息");
		try {
			//TODO 补全case代码
			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));			
			JSellerPromotionCallService.CancelOrEndPromotion(sellerid);

			CreateSellerPromotionBean createSellerPromotionBean = JSellerPromotionCallService.initCreateSellerPromotionBeanForSpeicalProduct(sellerid, PromotionTypeEnum.ReduceIfCountEnough);
			int promotionId = JSellerPromotionCallService.CreateSellerPromotion(createSellerPromotionBean);
			
			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
//			getpromotionproductbyidBean.setSellerId(94);
//			getpromotionproductbyidBean.setPromotionId(721);
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			GetPromotionProductByIdResp resp = getpromotionproductbyidCall.getPromotionProductByIdResp();
			
			Logger.verifyEquals(2, resp.getProductType(), "验证返回Code");

			List<String> productIds = resp.getProductIds();
			for(int i=0;i<productIds.size();i++)
			{
				Logger.verifyEquals(createSellerPromotionBean.getPromotionInfo().getProductIds().get(i), productIds.get(i), "验证返回ProductId");

			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionProductById_002() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-活动已取消");
		try {
			//TODO 补全case代码
			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));			
			JSellerPromotionCallService.CancelOrEndPromotion(sellerid);

			CreateSellerPromotionBean createSellerPromotionBean = JSellerPromotionCallService.initCreateSellerPromotionBeanForSpeicalProduct(sellerid, PromotionTypeEnum.ReduceIfCountEnough);
			int promotionId = JSellerPromotionCallService.CreateSellerPromotion(createSellerPromotionBean);
			JSellerPromotionCallService.CancelOrEndPromotion(sellerid);

			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals("null", getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionProductById_003() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-活动未开始");
		try {
			//TODO 补全case代码
			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));			
			JSellerPromotionCallService.CancelOrEndPromotion(sellerid);

			CreateSellerPromotionBean createSellerPromotionBean = JSellerPromotionCallService.initCreateSellerPromotionBeanForSpeicalProduct(sellerid, PromotionTypeEnum.ReduceIfCountEnough);
			
			createSellerPromotionBean.getPromotionInfo().setPromotionBeginTime(YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING));
			createSellerPromotionBean.getPromotionInfo().setPromotionEndTime(YMTDateUtil.getBeforeOrNextDay(2, YMTDateUtil.YMDTHMS_STRING));

			int promotionId = JSellerPromotionCallService.CreateSellerPromotion(createSellerPromotionBean);
			JSellerPromotionCallService.CancelOrEndPromotion(sellerid);

			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals("null", getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_GetPromotionProductById_004() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-新老接口对比-待完善");
		try {
			

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProductById_005() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-sellerId空");
		try {

			getpromotionproductbyidBean.setPromotionId(1);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals("null", getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProductById_006() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-promotionId空");
		try {
			//TODO 补全case代码
			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));			

			getpromotionproductbyidBean.setSellerId(sellerid);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals("null", getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProductById_007() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-sellerid与promotionId不一致");
		try {
			//TODO 补全case代码
			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));			

			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(54545);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals("null", getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_GetPromotionProductById_008() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-新老接口对比");
		try {
			//TODO 补全case代码
			int sellerid = TestDataManager.getRandomIntNum(6);			
			JSellerPromotionCallService.CancelOrEndPromotion(sellerid);

			CreateSellerPromotionBean createSellerPromotionBean = JSellerPromotionCallService.initCreateSellerPromotionBeanForSpeicalProduct(sellerid, PromotionTypeEnum.ReduceIfCountEnough);
			int promotionId = JSellerPromotionCallService.CreateOldSellerPromotion(createSellerPromotionBean);
			Thread.sleep(1000);

			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
//			getpromotionproductbyidBean.setSellerId(94);
//			getpromotionproductbyidBean.setPromotionId(721);
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			GetPromotionProductByIdResp resp = getpromotionproductbyidCall.getPromotionProductByIdResp();
			
			Logger.verifyEquals(2, resp.getProductType(), "验证返回Code");

			List<String> productIds = resp.getProductIds();
			List<String> productIds4 = new ArrayList<>();
			for(int i=0;i<productIds.size();i++)
			{
				productIds4.add(createSellerPromotionBean.getPromotionInfo().getProductIds().get(i));
			}
			
			Logger.verifyEquals(true, new PromotionInfoVerify().checkStringList(productIds, productIds4), "验证返回ProductId");

			
			String url = getpromotionproductbyidCall.getUrl();
			url=url.replace("reachpromotion.iapi.ymatou.com", "sellerpromotion.api.ymatou.com");
		
			getpromotionproductbyidCall.setUrl(url);			
			getpromotionproductbyidCall.callService();	
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			GetPromotionProductByIdResp resp2 = getpromotionproductbyidCall.getPromotionProductByIdResp();
			
			Logger.verifyEquals(2, resp2.getProductType(), "验证返回Code");

			List<String> productIds2 = resp2.getProductIds();
			List<String> productIds3 = new ArrayList<>();
			for(int i=0;i<productIds.size();i++)
			{
				productIds3.add(createSellerPromotionBean.getPromotionInfo().getProductIds().get(i));
			}
			
			Logger.verifyEquals(true, new PromotionInfoVerify().checkStringList(productIds2, productIds3), "验证返回ProductId");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_GetPromotionProductById_009() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-新老接口对比-stg");
		try {
			//TODO 补全case代码
			int sellerid = 3207973;		
			int promotionId = 16983;

			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			GetPromotionProductByIdResp resp = getpromotionproductbyidCall.getPromotionProductByIdResp();
			
			String url = getpromotionproductbyidCall.getUrl();
			url=url.replace("reachpromotion.iapi.ymatou.com", "sellerpromotion.api.ymatou.com");
		
			getpromotionproductbyidCall.setUrl(url);			
			getpromotionproductbyidCall.callService();	
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			GetPromotionProductByIdResp resp2 = getpromotionproductbyidCall.getPromotionProductByIdResp();
			
			AssertHelper.assertResultEqual(resp, resp2, "GetPromotionProductById");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}